package Card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    public static final String[] suits = {"♠","♥","♣","♦"};
    
    //买一副牌，也就是对牌进行初始化
    public static final List<Card> buyCard(){
        List<Card> cards = new ArrayList<Card>(52);
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j <= 13; j++) {
                String tempSuit = suits[i];
                int tempRank = j;
                Card newCard = new Card();
                newCard.setSuit(suits[i]);
                newCard.setRank(j);
                cards.add(newCard);
            }
        }
        return cards;
    }
    
    //洗牌
    public void swap(List<Card> cards,int i,int j){
        Card tempCard = cards.get(i);
        cards.set(j,tempCard);
        cards.set(i,cards.get(j));
    }
    
    //洗牌
    public void shuffle(List<Card> cards){
        Random random = new Random();
        for (int i = cards.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cards,index,i);
        }
    }
    //发牌
    public List<List<Card>> dealCard(List<Card> cardList){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card tempCard = cardList.remove(0);
                hands.get(j).add(tempCard);
            }
        }
        return hands;
    }
}
